package pers.mor.tomcat.http;

import cn.hutool.system.SystemUtil;

import java.io.File;

public class Constant {

    public static final int CODE_200 = 200;
    public static final int CODE_302 = 302;
    public static final int CODE_404 = 404;
    public static final int CODE_500 = 500;

    public static final String localhost = "127.0.0.1";

    /**
     *  不声明http版本，状态和mineType，浏览器也是能接收数据并显示出来的。
     *  但无法识别内容类型，在控制台中只能看到请求头但看不到响应头，无响应状态。
     *  最后面必须加上"\r\n\r\n"，因为只有隔开2个空行，浏览器才能识别到后面的是服务器响应的内容
     */
    public static final String response_head_200 =
            "HTTP/1.1 200 OK\r\n" + "Content-Type: {};{}" + "{}" + "\r\n\r\n";

    public static final String response_head_200_gzip =
            "HTTP/1.1 200 OK\r\n" + "Content-Type: {};{}" + "{}" +
                    "\r\nContent-Encoding: gzip" +
                    "\r\n\r\n";

    public static final String response_head_302 =
            "HTTP/1.1 302 Found\r\n" + "Content-Type: {};{}" + "{}" +
                    "\r\nLocation: {}" +
                    "\r\n\r\n";

    public static final String response_head_404 =
            "HTTP/1.1 404 Not Found\r\n" + "Content-Type: {};{}" + "{}" + "\r\n\r\n";

    public static final String textFormat_404 =
            "<html><head><title>JerryMouse/1.0.1 - Error report</title><style>" +
                    "<!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} " +
                    "H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} " +
                    "H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} " +
                    "BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} " +
                    "B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} " +
                    "P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}" +
                    "A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> " +
                    "</head><body><h1>HTTP Status 404 - {} </h1>" +
                    "<HR size='1' noshade='noshade'><p><b>type</b> Status report</p><p><b>message</b> <u>{}</u></p><p><b>description</b> " +
                    "<u>The requested resource is not available.</u></p><HR size='1' noshade='noshade'><h3>JerryMouse 1.0.1</h3>" +
                    "</body></html>";

    public static final String response_head_500 =
            "HTTP/1.1 500 Internal Server Error\r\n" + "Content-Type: {};{}" + "{}" + "\r\n\r\n";

    public static final String textFormat_500 = "<html><head><title>JerryMouse/1.0.1 - Error report</title><style>"
            + "<!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} "
            + "H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} "
            + "H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} "
            + "BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} "
            + "B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} "
            + "P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}"
            + "A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> "
            + "</head><body><h1>HTTP Status 500 - An exception occurred processing {}</h1>"
            + "<HR size='1' noshade='noshade'><p><b>type</b> Exception report</p><p><b>message</b> <u>An exception occurred processing {}</u></p><p><b>description</b> "
            + "<u>The server encountered an internal error that prevented it from fulfilling this request.</u></p>"
            + "<p>Stacktrace:</p>" + "<pre>{}</pre>" + "<HR size='1' noshade='noshade'><h3>JerryMouse 1.0.1</h3>"
            + "</body></html>";

    public static final File webappsFolder =
            new File(SystemUtil.get("user.dir"), "webapps");

    public static final File rootFolder =
            new File(webappsFolder, "ROOT");

    public static final File confFolder =
            new File(SystemUtil.get("user.dir"), "conf");

    public static final File serverXmlFile =
            new File(confFolder, "server.xml");

    public static final File webXmlFile =
            new File(confFolder, "web.xml");

    public static final File contextXmlFile =
            new File(confFolder, "context.xml");
}
